package com.xyhuo.leetcode.june;

/**
 * 171. Excel表列序号
 * https://leetcode.cn/problems/excel-sheet-column-number/
 */
public class TitleToNumber {

    public int titleToNumber(String columnTitle) {
        char[] charArray = columnTitle.toCharArray();
        int ans = 0;
        for (int i = charArray.length - 1; i >= 0; i--) {
            double value = (charArray[i] - 'A' + 1) * Math.pow(26, charArray.length - i - 1);
            ans += value;
        }
        return ans;
    }
}
